$(function () {
  // 添加选中样式
  $('.component-header .nav-box').children('.' + $('.container-header').attr('data-type')).addClass('active')
  $('.component-header .nav-list ul').children('.' + $('.container-header').attr('data-type')).addClass('active')
  // 是否加载完成
  var loadSystemEnd = false
  var loadBasicEnd = false
  // 获取系统配置
  function getSystemInfo() {
    $.ajax({
      method: 'GET',
      url: adminPath + '/api/wdsxh/system/conf',
      success: function (res) {
        // 加载完成
        loadSystemEnd = true
        if (loadSystemEnd && loadBasicEnd) {
          $(".container-fluid").css("opacity", 1)
        }
        if (res.code == 1) {
          // 设置主题色
          $("body")[0].style.setProperty('--main-color', res.data.theme_color)
          // 设置版本选择
          $(".versionName").text(res.data.navtext)
          // 设置新闻页标题
          if ($('.news-container').length > 0) {
            $("title").text(res.data.navtext + "新闻")
          }
        } else {
          console.error(res.msg)
        }
      },
    })
  }
  // 获取商会信息
  function getBasicInfo() {
    $.ajax({
      method: 'GET',
      url: adminPath + '/api/wdsxh/coceral/info',
      success: function (res) {
        // 加载完成
        loadBasicEnd = true
        if (loadSystemEnd && loadBasicEnd) {
          $(".container-fluid").css("opacity", 1)
        }
        if (res.code == 1) {
          // 设置页头信息
          $(".component-header .header-top .name").text(`欢迎进入${res.data.name}官方网站！`)
          $(".component-header .nav-logo img").attr("src", res.data.logo)
          $(".component-header .nav-logo .title").text(res.data.name)
          // 设置页脚信息
          $(".component-footer .footer-logo img").attr("src", res.data.logo)
          $(".component-footer .footer-logo .title").text(res.data.name)
          $(".component-footer .footer-info .address").append(res.data.address)
          $(".component-footer .footer-info .phone").append(res.data.phone)
          $(".component-footer .footer-info .email").append(res.data.email)
          $(".component-footer .footer-info span b").text(res.data.name)
          // 设置首页
          if ($('.index-container').length > 0) {
            $(".index-container .column-1 .cont-left").text(res.data.brief)
            $(".index-container .column-1 .cont-right img").attr("src", res.data.thumbnail)
            $(".index-container .column-2 .title span").text(res.data.name + "期待你的加入")
          }
          // 设置关于我们
          if ($('.about-container').length > 0) {
            var indicatorsHtml = ""
            var innerHtml = ""
            for (var i in res.data.pc_images) {
              indicatorsHtml += `<li data-target="#carouselExampleIndicators" data-slide-to="${i}" ${i == 0 ? 'class="active"' : ''}></li>`
              innerHtml += `
                <div class="carousel-item ${i == 0 ? 'active' : ''}">
                  <img src="${res.data.pc_images[i]}" class="w-100 normal">
                  <img src="${res.data.images[i]}" class="w-100 mobile">
                </div>
              `
            }
            $(".about-container #carouselExampleIndicators .carousel-indicators").html(indicatorsHtml)
            $(".about-container #carouselExampleIndicators .carousel-inner").html(innerHtml)
            $(".about-container .main-content p").html(res.data.introduce)
            $(".about-container .main-content img").attr("src", res.data.offiaccount)
          }
          // 设置联系我们
          if ($('.contact-container').length > 0) {
            $(".contact-container .main-content .address").text(res.data.address)
            $(".contact-container .main-content .phone").text(res.data.phone)
            $(".contact-container .main-content .email").text(res.data.email)
            $(".contact-container .main-content .item-code").attr("src", res.data.offiaccount)
          }
        } else {
          console.error(res.msg)
        }
      },
    })
  }
  // 移动端导航菜单点击
  var isExpand = 1;
  $('#navbar').on('click', function (event) {
    event.stopPropagation()
    if (isExpand == 1) {
      $(this).css("transform", 'rotate(90deg)');
      $('.nav-mobile .nav-list').stop().fadeIn();
      isExpand = 2;
    } else {
      $(this).css("transform", 'rotate(0deg)');
      $('.nav-mobile .nav-list').stop().fadeOut();
      isExpand = 1;
    }
  })
  // 点击其他地方关机手机端导航框
  $('body').click(function () {
    $('#navbar').css("transform", 'rotate(0deg)');
    $('.nav-mobile .nav-list').stop().fadeOut();
    isExpand = 1;
  })
  // 调用方法
  getSystemInfo()
  getBasicInfo()
})